package org.gwu.seuss.server.command;

import org.gwu.seuss.communication.request.Actions;
import org.gwu.seuss.communication.request.ClientRequest;
import org.gwu.seuss.communication.request.ServerResponse;

public class UploadCommand extends UserCommandBase implements Command {

	public UploadCommand(ClientRequest req) {
		super(req);
	}

	@Override
	public ServerResponse execute() throws Exception {
		userService.actionAllowed(req.getUsername(), Actions.UPLOAD);
		log.info("User " +  req.getUsername() + "requested to upload file " + req.getFileName());

		int result = fileService.uploadFile(req);

		return getServerResponse(result, req.getFileName() + " has been uploaded");
	}
}